package com.iweibo.ui;

import java.io.IOException;

import com.iweibo.R;
import com.weibo.sdk.android.Oauth2AccessToken;
import com.weibo.sdk.android.WeiboException;
import com.weibo.sdk.android.api.StatusesAPI;
import com.weibo.sdk.android.api.WeiboAPI.FEATURE;
import com.weibo.sdk.android.net.RequestListener;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;

/**
 * 主页页面Activity
 * @author nibo
 * @date 2012-11-21
 *
 */
public class HomeActivity extends Activity {

	private static final String TAG = "HomeActivity";
	
	//主界面上部标题View
	private View titleBarView = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        Log.d(TAG, getResources().getText(R.string.home).toString());
        
        Intent userInfoIntent = getIntent();
        long userId = userInfoIntent.getLongExtra("user_id" , -1);
        String userName = userInfoIntent.getStringExtra("user_name");
        String token = userInfoIntent.getStringExtra("token");
        int expiresIn = userInfoIntent.getIntExtra("expires_in", -1);
        
        Log.d(TAG, "user_id:" + userId);
        Log.d(TAG, "user_name:" + userName);
        Log.d(TAG, "token:" + token);
        Log.d(TAG, "expires_in:" + expiresIn);
//        titleBarView = findViewById(R.layout.titlebar);
//        TextView tvUserName = (TextView)titleBarView.findViewById(R.id.tv_user_name);
//        //设置标题显示的用户名
//        tvUserName.setText(userName);
        
        StatusesAPI statusesAPI = new StatusesAPI(new Oauth2AccessToken(token, String.valueOf(expiresIn)));
        statusesAPI.homeTimeline(0, 0, 50, 1, false, FEATURE.ALL, false, listener);
    }
    
    private RequestListener listener = new RequestListener() {

		@Override
		public void onComplete(String response) {
			Log.d(TAG, "获取用户好友微博信息成功!");
			
//			System.out.println(response);
		}

		@Override
		public void onComplete(byte[] response) {
			super.onComplete(response);
		}

		@Override
		public void onIOException(IOException e) {
			Log.e(TAG, "获取用户好友微博信息出错!" + e.getMessage());
		}

		@Override
		public void onError(WeiboException e) {
			Log.e(TAG, "获取用户好友微博信息出错!" + e.getMessage() + "|状态码(" + e.getStatusCode() + ")");
		}
    	
	};
    
}
